
<!DOCTYPE html>
<html>
  <head>
    <title>module folktale/core/lambda</title>
    <link rel="stylesheet" href="prism.css">
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <div id="header">
      <div class="doc-title"><a href="folktale.html"><span class="doc-title"><span class="product-name">Folktale</span><span class="version">v2.0.1</span></span></a><ul class="navigation"><li class="navigation-item"><a href="https://github.com/origamitower/folktale" title="">GitHub</a></li><li class="navigation-item"><a href="folktale.html#cat-2-support" title="">Support</a></li><li class="navigation-item"><a href="folktale.html#cat-3-contributing" title="">Contributing</a></li></ul></div>
    </div>
    <div id="content-wrapper"><div id="content-panel"><h1 class="entity-title">module folktale/core/lambda</h1><div class="highlight-summary"><div><p>Core.Lambda provides you tools for transforming and combining
functions.</p>
</div></div><h2 class="section-title">Documentation</h2><div class="documentation"><div><p>Core.Lambda provides you tools for transforming and combining
functions.</p>
<h2 id="programming-by-combining-functions">Programming by Combining Functions</h2>
<p>Functional programming places a heavy emphasis on writing programs
by combining lots of small, focused functions. JavaScript doesn&#39;t
really have a good support for this out of the box, so you&#39;re left
with composing these functions manually, by defining a new function.</p>
<p>This is not so bad in ECMAScript 2015, thanks to the new arrow
function syntax:</p>
<pre><code>const people = [
  { name: &#39;Alissa&#39; },
  { name: &#39;Max&#39; },
  { name: &#39;Talib&#39; }
];
people.map(person =&gt; person.name);
// ==&gt; [&#39;Alissa&#39;, &#39;Max&#39;, &#39;Talib&#39;]
</code></pre><p>But there are times in which arrow functions don&#39;t quite cut it.
For example, if one wants to evaluate something eagerly, a constant
combinator makes more sense:</p>
<pre><code>const counter = {
  value: 0,
  next()  { return ++this.value },
  reset() { this.value = 0 }
};
const constant = require(&#39;folktale/core/lambda/constant&#39;);

counter.reset();
[0, 0, 0].map(constant(counter.next()));
// ==&gt; [1, 1, 1]

// Arrows are evaluated lazily, so they don&#39;t work for this
counter.reset();
[0, 0, 0].map(_ =&gt; counter.next());
// ==&gt; [1, 2, 3]

// One must store the value somewhere instead
counter.reset();
[0, 0, 0].map((x =&gt; _ =&gt; x)(counter.next()))
</code></pre><h2 id="what-s-in-core-lambda-">What&#39;s in Core.Lambda?</h2>
<p>Core.Lambda provides combinators and operations that transform the
signature of a function. The operations in the module are divided
as thus:</p>
<ul>
<li><p><strong>Combining</strong>: contains functions that combines functionality
present in different functions into a single function. Composing
functions is an example.</p>
</li>
<li><p><strong>Combinators</strong>: functions that just re-arrange the arguments
they&#39;re given. They&#39;re convenient ways of writing a particular
operation, but don&#39;t have any special behaviour of their own,
nor use anything besides the arguments they&#39;re given. Constant
and Identity are common combinators.</p>
</li>
<li><p><strong>Currying and Partialisation</strong>: functions that transform
how parameters are provided to a function. Currying allows a
function to take parameters one at a time, whereas partialisation
allows one to provide some of the positional parameters without
executing the function before the rest is provided.</p>
</li>
</ul>
</div></div><div class="members"><h2 class="section-title" id="properties">Properties</h2><div class="member-category"><h3 class="category" id="cat-function-composition">Function composition</h3><div class="member-list"><div class="member"><a class="member-name" href="folktale.core.lambda.compose.compose.html">compose(f, g)(value)</a><div class="doc-summary"><div><p>Composes two functions.</p>
</div></div><div class="special-tags"></div></div></div></div><div class="member-category"><h3 class="category" id="cat-functional-combinators">Functional combinators</h3><div class="member-list"><div class="member"><a class="member-name" href="folktale.core.lambda.constant.constant.html">constant(value)</a><div class="doc-summary"><div><p>The constant combinator; always returns the first argument given.</p>
</div></div><div class="special-tags"></div></div><div class="member"><a class="member-name" href="folktale.core.lambda.identity.identity.html">identity(value)</a><div class="doc-summary"><div><p>The identity combinator; always returns the argument given.</p>
</div></div><div class="special-tags"></div></div></div></div><div class="member-category"><h3 class="category" id="cat-partialization-currying">Partialization / Currying</h3><div class="member-list"><div class="member"><a class="member-name" href="folktale.core.lambda.curry.curry.html">curry(arity, fn)</a><div class="doc-summary"><div><p>Transforms functions of arity N into a chain of N unary functions</p>
</div></div><div class="special-tags"><span class="tagged experimental">Experimental</span></div></div><div class="member"><a class="member-name" href="folktale.core.lambda.partialize.partialize.html">partialize(arity, fn)</a><div class="doc-summary"><div><p>Creates a new function where some of the arguments are specified.</p>
</div></div><div class="special-tags"><span class="tagged experimental">Experimental</span></div></div></div></div></div><div class="source-code"><h2 class="section-title" id="source-code">Source Code</h2><div class="source-location">Defined in source/core/lambda/index.js at line 14, column 0</div><pre class="source-code"><code class="language-javascript">{
  identity: require('./identity'),
  constant: require('./constant'),
  curry: require('./curry'),
  compose: require('./compose'),
  partialize: require('./partialize')
}</code></pre></div></div><div id="meta-panel"><div class="meta-section"><div class="meta-field"><strong class="meta-field-title">Stability</strong><div class="meta-field-value">stable</div></div><div class="meta-field"><strong class="meta-field-title">Licence</strong><div class="meta-field-value">MIT</div></div><div class="meta-field"><strong class="meta-field-title">Module</strong><div class="meta-field-value">folktale/core/lambda</div></div></div><div class="table-of-contents"><div class="meta-section-title">On This Page</div><ul class="toc-list level-1"><li class="toc-item"><span class="no-anchor">Documentation</span><ul class="toc-list level-2"><li class="toc-item"><a href="#programming-by-combining-functions" title="Programming by Combining Functions"><div><p>Programming by Combining Functions</p>
</div></a></li><li class="toc-item"><a href="#what-s-in-core-lambda-" title="What's in Core.Lambda?"><div><p>What&#39;s in Core.Lambda?</p>
</div></a></li></ul></li><li class="toc-item"><a href="#properties">Properties</a><ul class="toc-list level-2"><li class="toc-item"><a href="#cat-function-composition">Function composition</a></li><li class="toc-item"><a href="#cat-functional-combinators">Functional combinators</a></li><li class="toc-item"><a href="#cat-partialization-currying">Partialization / Currying</a></li></ul></li><li class="toc-item"><a href="#source-code">Source Code</a></li></ul></div><div class="meta-section"><strong class="meta-section-title">Authors</strong><div class="meta-field"><strong class="meta-field-title">Copyright</strong><div class="meta-field-value">(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS</div></div><div class="meta-field"><strong class="meta-field-title">Authors</strong><div class="meta-field-value"><ul class="meta-list"><li>Quildreen Motta</li></ul></div></div><div class="meta-field"><strong class="meta-field-title">Maintainers</strong><div class="meta-field-value"><ul class="meta-list"><li>Quildreen Motta &lt;queen@robotlolita.me&gt; (http://robotlolita.me/)</li></ul></div></div></div></div></div>
    <script>
void function() {
  var xs = document.querySelectorAll('.documentation pre code');
  for (var i = 0; i < xs.length; ++i) {
    xs[i].className = 'language-javascript code-block';
  }
}()
    </script>
    <script src="prism.js"></script>
  </body>
</html>